#include<bits/stdc++.h>
using namespace std;
long long k,n,x,a[1000000],ans,ma;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>k;
    while(k--){
        cin>>n;
        memset(a,0,sizeof(a));
        ma=-1;
        while(n--){
            cin>>x;
            a[x]++;
            ma=max(ma,x);
        }
        ans=0;
        for(int i=ma;i>=1;i--){
            if(a[i]>=2)ans+=i*(a[i]-1);
        }
        cout<<ans<<"\n";
    }
    return 0;
}
